<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css" />
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css" />
    <link href="css/mian.css" rel="stylesheet" />
    <link href="font/iconfont.css" rel="stylesheet" />
    <title>无忧考吧</title>
</head>
<body>
    <div class="page">
        <header class="bar bar-nav head-bg">
            <a class="button button-link button-nav pull-left aff" href="javascript:history.back();" data-transition='slide-out' style="color: #fff; font-size: 0.7rem">
                <span class="icon icon-left" style="color: #fff; font-size: 0.7rem"></span>
                返回
            </a>
            <h1 class="title">选择科目</h1>
        </header>

        <div class="content" style="background: #fff;">
            <!-- 这里是页面内容区 -->
            <div class="subject-list">
            </div>

        </div>
    </div>
    <script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
    <script>
        $.config = { router: false }
    </script>
    <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
    <script type='text/javascript'>

        $.ajax({
            url: "Action/Ajax.ashx",
            type: "post",
            data: {
                action: "getallsubjects",
            }, async: false,
            cache: false,
            success: function (result) {
                if (result == "-1" || result == "-2") {

                    location.href = "/Exam/UserNotAvail.aspx";
                    return;
                }
                result = $.parseJSON(result);
                todo(result);
            }
        });
        function todo(result) {
            var content = "";
            //if ("1" != "0") {
            //    for (var i = 0; i < result.length; i++) {
            //if (result[i].TestType == 0) {
            //        content += '<a href="Exam.aspx?istry=1&subjectid=' + result[i].SubjectInfoID + '">' + result[i].SubjectName + '</a>';
            //continue;
            //}
            //content += '<a href="javascript:showtrymsg(' + result[i].SubjectInfoID + ','+result[i].ActivCode+');" data-ActivCode="' + result[i].ActivCode + '">' + result[i].SubjectName + '</a>';
            //    }
            //}
            //else {

            for (var i = 0; i < result.length; i++) {
                content += '<a href="javascript:;" onclick="showtrymsg(' + result[i].SubjectInfoID + ',\'' + result[i].ActivCode + '\',this);">' + result[i].SubjectName + '</a>';
            }

            //}
            $(".subject-list").html(content);
        }
        function showtrymsg(sid, code, obj) {
            if ('' == '1') {
                $.confirm('是否激活科目:' + $(obj).text(), function () {
                    $.post("Action/Login.ashx", { action: "firstActiveBySbj", sid: sid, code: code }, function (ret) {
                        if (ret.indexOf("|") != -1) {
                            var result = ret.split('|')[0];
                            if (result == 'True') {
                                $("a").attr("onclick", '');
                                var sid = ret.split('|')[1]
                                showinfo(sid);
                            }
                            else if (result == 'False') {
                                $.alert("此卡号已被激活 确认后跳转", function () {
                                    history.back();
                                });
                            }
                            else if (result == "exist") {
                                $.alert('该科目已激活或卡号已使用，请重新选择 或 点击[返回]！')
                            }
                        }
                        else if (ret == "exist") {
                            $.alert('该科目已激活或卡号已使用，请重新选择 或 点击[返回]！')
                        }
						else if (ret == "notVIP") {
                                $.alert('VIP卡不允许激活该科目，请重新选择 或 点击[返回]！')
                            }
                        else {
                            console.log(ret);
                            $.alert('出现错误 请重试或联系客服');
                        }
                    });
                })
            }
            else {
                $.post("Action/Login.ashx", { action: "checkExist", sid: sid }, function (ret) {
                    if (ret == "True") {

                        //if ("" == "0") {
                        //    $.confirm('本科目需要激活方可继续，是否去激活?', function () {
                        //        location.href = "login.aspx?code=" + code + "&sid=" + sid;
                        //    });
                        // }
                        //else{
                        location.href = 'Exam.aspx?istry=1&subjectid=' + sid;
                        // }

                    }
                    else {
                        location.href = 'Exam.aspx?istry=0&subjectid=' + sid;
                    }
                })
            }
        }

        function showinfo(sid) {
            $.post("Action/Login.ashx?ref" + new Date().getTime(), { action: "activeinfo", sid: sid }, function (ret) {
                ret = $.parseJSON(ret);


                $.alert("当前激活的科目为" + ret[0].SubjectName + ",有效期至" + ret[0].EndTime, function () {
                    location.href = "Exam.aspx?istry=0&subjectid=" + sid;
                });
            })
        }
    </script>
    <script>$.init()</script>
</body>
</html>
